import BaseModel from "../model/baseModel.js";

/**
 * insert语句拼接
 * @param {Array} arr 
 */
function JoinSQLInsertKeys(arr) {
    let s = "(";
    for (let i = 0; i < arr.length; i++) {
        s += `${arr[i]}` + ',';
    }
    s = s.substring(0, s.length - 1);
    s += ')';
    s += 'values ?'
    return s;
}


/**
 * 修改语句查询
 * @param {Map} data
 * @param {BaseModel} model
 */
function JoinSQLUpdateKeys(data, model) {
    let s = 'set '
    for (const key in data) {
        if (Object.hasOwnProperty.call(data, key)) {
            const element = data[key];
            s += `${key} = ${element},`
        }
    }
    s = s.substring(0, s.length - 1)
    s += `\twhere id = '${model.id}'`
    return s
}

export {
    JoinSQLInsertKeys,
    JoinSQLUpdateKeys
}